unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, Buttons;

type
    ukaz= ^zapis;
   zapis= record
     Fio,Add: string [70];
     Ntel: word;
     Next: ukaz;                    
    end;

  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    SaveDialog1: TSaveDialog;
    OpenDialog1: TOpenDialog;
    Edit1: TEdit;
    Button1: TButton;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    Edit2: TEdit;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Edit3: TEdit;
    Label3: TLabel;
    Edit4: TEdit;
    N10: TMenuItem;
    Memo1: TMemo;
    Button4: TButton;
    procedure FormActivate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure N10Click(Sender: TObject);
    procedure N8Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  A,B:ukaz;
  F: file of ukaz;

implementation

uses Unit2;

{$R *.dfm}






procedure TForm1.FormActivate(Sender: TObject);
begin
new(A); A^.Fio:=''; A^.Add:=''; A^.Ntel:=0; A^.Next:=nil;


end;




procedure TForm1.Button2Click(Sender: TObject);
var x,c: integer;

begin

new(B);
B^.Fio:=Edit1.Text;
B^.Add:=Edit2.Text;
val (Edit3.Text,x,c);
if c=0 then  begin

 B^.Ntel:=x;
 B^.Next:=A;   A:=B;
 
Memo1.Lines.Add('');
Memo1.Lines.Add(B^.Fio);
Memo1.Lines.Add(B^.Add);
Memo1.Lines.Add(IntToStr(B^.Ntel));


Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:=''; end

else  MessageDlg('Ââåäèòå íîìåð!',MtError,[MbOk],0);

end;




procedure TForm1.Button1Click(Sender: TObject);
var key: string [70]; pr: boolean;
      x: integer;
begin
memo1.Clear;  memo1.Lines.Add('Ðåç-òû ïîèñêà:');

key:=Edit4.Text;  pr:=true;

repeat

x:=pos(key,B^.Fio);

if x<>0 then begin
   pr:=false;
   Memo1.Lines.Add('');
   Memo1.Lines.Add(B^.Fio);
   Memo1.Lines.Add(B^.Add);
   Memo1.Lines.Add(IntToStr(B^.Ntel));  end
else begin
 x:=pos(key,B^.Add);

     if x<>0 then begin
         pr:=false;
         Memo1.Lines.Add('');
         Memo1.Lines.Add(B^.Fio);
         Memo1.Lines.Add(B^.Add);
         Memo1.Lines.Add(IntToStr(B^.Ntel));  end; end;

B:=B^.Next;

until B^.Next=nil;

if pr then
 memo1.Lines.Add('Íè÷åãî íå íàéäåíî!');

B:=A;

end;






procedure TForm1.Button3Click(Sender: TObject);
var prev,nxt: ukaz;
    nt1,nt2: word;
    F1,F2,Ad1,Ad2: string[70];
    i,j,n: byte;

begin
memo1.Clear;  memo1.Lines.Add('Çàïèñíàÿ êíèãà :');
n:=0;     Nxt:=A;

repeat
n:=n+1;
Nxt:=Nxt^.Next;
until Nxt^.Next=nil;


for i:=1 to n do  begin

Nxt:=A^.Next; Prev:=A;

 for j:=1 to (n-i) do begin

 if Nxt^.Fio<Prev^.Fio then begin
 F1:=Nxt^.Fio;  F2:=Prev^.Fio;
 Ad1:=Nxt^.Add; Ad2:=Prev^.Add;
 nt1:=Nxt^.Ntel; nt2:=Prev^.Ntel;

 Prev^.Fio:=F1;    Nxt^.Fio:=F2;
 Prev^.Add:=Ad1;   Nxt^.Add:=Ad2;
 Prev^.Ntel:=nt1;  Nxt^.Ntel:=nt2;

 Nxt:=Nxt^.Next; Prev:=Prev^.Next;  end;

 end; end;

repeat
memo1.Lines.Add('');
memo1.Lines.Add(A^.Fio);
memo1.Lines.Add(A^.Add);
memo1.Lines.Add(IntToStr(A^.Ntel));
A:=A^.Next;

until A^.Next=nil;
A:=B;


end;



procedure TForm1.N2Click(Sender: TObject);
begin
if OpenDialog1.Execute then  begin
  memo1.Clear;
  memo1.Lines.LoadFromFile(OpenDialog1.FileName); end;
end;




procedure TForm1.N3Click(Sender: TObject);
begin
if SaveDialog1.Execute then
 memo1.Lines.SaveToFile(SaveDialog1.FileName);

end;





procedure TForm1.N5Click(Sender: TObject);
begin
repeat
A:=A^.Next; dispose(B);
B:=A;
until A^.Next=nil;
dispose(A);
memo1.Free; memo1.Lines.Add('Çàïèñíàÿ êíèæêà: ');
end;



procedure TForm1.Button4Click(Sender: TObject);
begin
repeat
A:=A^.Next; dispose(B);
B:=A;
until A^.Next=nil;
dispose(A);
close;
end;

procedure TForm1.N10Click(Sender: TObject);
begin
repeat
A:=A^.Next; dispose(B);
B:=A;
until A^.Next=nil;
dispose(A);
close;
end;

procedure TForm1.N8Click(Sender: TObject);
begin
AboutBox.show;
end;

end.
